package org.tech4j.common.core.sign.extractor.parse;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.tech4j.common.spi.Join;
import org.tech4j.common.core.request.param.ParameterDataFactory;

import java.util.Map;

/**
 * @program: tech4j-common
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/2 20:52
 **/
@Join
public class QueryParseData implements ParseData {

    @Override
    public Triple<Map<String, Object>, String, String> parse(String paramType, String paramKey, HttpServletRequest request) {
        Map<String, Object> data = ParameterDataFactory.buildMapData(paramType, paramKey, request);
        if (data == null || data.isEmpty()) {
            return null;
        }
        Object sign = data.get(paramKey);
        return ImmutableTriple.of(data, sign == null ? "" : sign.toString(), request.getQueryString());
    }
}
